//
//  MainViewController.swift
//  MySwiftDemo
//
//  Created by 陈新杰 on 2017/9/20.
//  Copyright © 2017年 陈新杰. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        addChildViewControllers()
    }

    ///添加所有的子视图控制器
    func addChildViewControllers() {
        
        tabBar.tintColor = UIColor.orange
        
        addChildViewController("Home", "首页", "tabbar_home")
        addChildViewController("Message", "消息", "tabbar_message_center")
        addChildViewController("Discover", "发现", "tabbar_discover")
        addChildViewController("Profile", "我", "tabbar_profile")
        
    }
    func addChildViewController(_ sbName: String,_ title: String,_ imageName: String) {
        
        let sb = UIStoryboard(name: sbName, bundle: nil)
        let nav = sb.instantiateInitialViewController() as! UINavigationController
        
        nav.title = title
        nav.topViewController?.title = title
        nav.tabBarItem.image = UIImage(named: imageName)
        nav.tabBarItem.selectedImage = UIImage(named: imageName+"_highlighted")
        
        addChildViewController(nav)
    }
}
